home *** CD-ROM | disk | FTP | other *** search
- /*
- File: AppleEventStuff.c
-
- Contains: Handlers for the 4 "required" events
-
- Written by: Chris White, Developer Technical Support
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- 9/28/95 CW First release
-
- */
-
-
- #ifndef __MIXEDMODE__
- #include <MixedMode.h>
- #endif
-
- #ifndef __GESTALT__
- #include <Gestalt.h>
- #endif
-
- #ifndef __APPLEEVENTS__
- #include <AppleEvents.h>
- #endif
-
-
-
-
-
- #ifndef __FRAGMENTTOOL__
- #include "FragmentTool.h"
- #endif
-
- #ifndef __PROTOTYPES__
- #include "Prototypes.h"
- #endif
-
- #ifndef __APPLEEVENTSTUFF__
- #include "AppleEventStuff.h"
- #endif
-
-
-
-
-
- //
- // Prototypes for those routines which are private to this source file
- //
-
- static pascal OSErr HandleOapp ( AEDescList* aevt, AEDescList* reply, long refCon );
- static pascal OSErr HandleQuit ( AEDescList* aevt, AEDescList* reply, long refCon );
- static pascal OSErr HandleOdoc ( AEDescList* aevt, AEDescList* reply, long refCon );
- static pascal OSErr HandlePdoc ( AEDescList* aevt, AEDescList* reply, long refCon );
-
-
-
-
- void InstallAppleEventHandlers ( void )
- {
- OSErr theErr;
- int32 theResult;
-
- theErr = Gestalt ( gestaltAppleEventsAttr, &theResult );
- if ( theErr == noErr )
- {
- AEInstallEventHandler ( kCoreEventClass, kAEOpenApplication, NewAEEventHandlerProc ( HandleOapp ), 0, false );
- AEInstallEventHandler ( kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerProc ( HandleOdoc ), 0, false );
- AEInstallEventHandler ( kCoreEventClass, kAEPrintDocuments, NewAEEventHandlerProc ( HandlePdoc ), 0, false );
- AEInstallEventHandler ( kCoreEventClass, kAEQuitApplication, NewAEEventHandlerProc ( HandleQuit ), 0, false );
- }
-
- return;
-
- } // InstallAppleEventHandlers
-
-
- //
- // When we get an "oapp" event, we've been launched without any
- // document to open. So, we'll create an untitled document.
- //
- pascal OSErr HandleOapp ( AEDescList* aevt, AEDescList* reply, long refCon )
- {
- DoNewDocument ( );
-
- return noErr;
- }
-
-
-
- //
- // The "odoc" and "pdoc" messages contain a list of aliases as the direct paramater.
- // This means that we'll need to extract the list, count the list's elements, and
- // then process each file in turn.
- // */
- pascal OSErr HandleOdoc ( AEDescList* aevt, AEDescList* reply, long refCon )
- {
- AEDesc fileListDesc = {'NULL', NULL};
- long numFiles;
- DescType actualType;
- long actualSize;
- AEKeyword actualKeyword;
- FSSpec oneFile;
- long index;
- OSErr err;
-
-
- // Extract the list of aliases into fileListDesc
- err = AEGetKeyDesc( aevt, keyDirectObject, typeAEList, &fileListDesc );
- if ( err ) goto CleanupAndBail;
-
- // Count the list elements
- err = AECountItems( &fileListDesc, &numFiles);
- if ( err ) goto CleanupAndBail;
-
- // Now get each file from the list and process it.
- // Even though the event contains a list of alises, the Apple Event Manager
- // will convert each alias to an FSSpec if we ask it to.
- for ( index = 1; index <= numFiles; index ++ )
- {
- err = AEGetNthPtr ( &fileListDesc, index, typeFSS, &actualKeyword,
- &actualType, (Ptr) &oneFile, sizeof ( oneFile ), &actualSize );
-
- #if DEBUGGING
- if ( err )
- DebugStrNum ( "\p AEGetNthPtr returned ", err );
- #endif
-
- if ( err )
- break;
-
- err = OpenDocument ( &oneFile, nil );
-
- #if DEBUGGING
- if ( err )
- DebugStrNum ( "\p OpenDocument returned ", err );
- #endif
-
- if ( err )
- break;
- }
-
-
- // Since we want to free all the storage this routine allocates,
- // we'll continue execution here.
-
- CleanupAndBail:
-
- AEDisposeDesc ( &fileListDesc );
- return err;
-
- } // HandleOdoc
-
-
-
- pascal OSErr HandlePdoc ( AEDescList* aevt, AEDescList* reply, long refCon )
- {
- return errAEEventNotHandled;
- }
-
-
-
- pascal OSErr HandleQuit ( AEDescList* aevt, AEDescList* reply, long refCon )
- {
- gQuit = true;
-
- return noErr;
- }
-
-
-
-
-